﻿/*
 * Copyright © 2011 Tristan Reeves, treeves@gmail.com
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
using System;
using System.Collections.Generic;
using System.Reflection;

namespace Sprinkles.Secondary
{
    public class DeploymentInfo
    {
        private Func<string> m_ParentNameFunc;
        private string m_Name;
        private readonly string[] m_Aliases;
        private readonly bool m_HasUserDefinedName;
        private readonly Type m_Type;
        private readonly List<Arg> m_ConstructorArgs = new List<Arg>();

        public void ChangeNameIfNecessary(string newName)
        {
            m_Name = (newName ?? "").Trim();
        }

        //static factory
        public string StaticFactoryMethodName { get; set; }
        public Type StaticFactoryMethodType { get; set; }

        //instance factory
        public string InstanceFactoryMethodNameFunc { get; set; }
        public Func<string> InstanceFactoryObjectName { get; set; }

        //callbacks
        public Action<object>[] PreinitCallbacks { get; set; }
        public Action<object>[] PostinitCallbacks { get; set; }

        //properties
        public KeyValuePair<PropertyInfo, object>[] PropertyCombinations { get; set; }

        public string Name { get { return m_Name; } }
        public string[] Aliases
        {
            get { return m_Aliases; }
        }

        public DeploymentInfo(string name, string[] aliases, bool hasUserDefinedName, Type type)
        {
            m_Name = name;
            m_Aliases = (aliases ?? new string[0]);
            m_HasUserDefinedName = hasUserDefinedName;
            m_Type = type;
        }
        public bool HasUserDefinedName
        {
            get { return m_HasUserDefinedName; }
        }
        public Type Type
        {
            get { return m_Type; }
        }
        public bool IsSingleton { get; set; }
        public bool IsLazyInit { get; set; }
        public string InitMethod { get; set; }
        public string DestroyMethod { get; set; }
        public Scope Scope { get; set; }
        public string[] DependsReferences { get; set; }
        public MethodOverrideInfo[] MethodOverrides { get; set; }
        public Arg[] ConstructorArgs { get { return m_ConstructorArgs.ToArray(); } }
        public bool IsAbstract { get; set; }
        public Func<string> ParentNameFunc
        {
            get { return m_ParentNameFunc; }
            set { m_ParentNameFunc = value; }
        }
        public Type[] DefaultForTypes { get; set; }

        public void AddConstructorArg(Arg arg)
        {
            m_ConstructorArgs.Add(arg);
        }
    }
}
